package com.xcjw.com.Fragment;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * @packname com.awl.com.basefragment
 * @filename BaseFragment
 * @date on 2018/7/12 15:15
 *****/
public abstract class BaseFragment extends Fragment {
      protected Activity mActivity;
      protected View mRootView;
      private boolean isFirstLoad = false;

      @Nullable
      @Override
      public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
            mRootView = inflater.inflate(getlayoutId(), container, false);
            initview();
            init();
            return mRootView;
      }

      protected abstract void onLazyLoad();

      protected abstract void initview();

      @Override
      public void onAttach(Context context) {
            super.onAttach(context);
            mActivity = getActivity();
      }

      public abstract void init();


      public abstract int getlayoutId();




      @SuppressWarnings("unchecked")
      protected <T extends View> T findViewById(int id) {
            if (mRootView == null) {
                  return null;
            }

            return (T) mRootView.findViewById(id);
      }
      @Override
      public void onDestroyView() {
            super.onDestroyView();
           // isFirstLoad = false;//视图销毁将变量置为false
      }
      @Override
      public void setUserVisibleHint(boolean isVisibleToUser) {
            super.setUserVisibleHint(isVisibleToUser);
//            if (isFirstLoad && isVisibleToUser) {//视图变为可见并且是第一次加载
//                  onLazyLoad();
//                  isFirstLoad = false;
//            }

      }

}